package cn.colins.raft.utils;

import java.util.concurrent.*;

/**
 * @Description
 * @Author czl
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2023/6/13
 */
public class ThreadPoolUtils {


    /**
     * @Author czl
     * @Description 给netty服务启动使用
     **/
    public static ExecutorService startNettyPool = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
            60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName("Raft-Netty-Pool");
                    return thread;
                }
            });

    /**
     * @Author czl
     * @Description 重试任务线程池
     **/
    public static ExecutorService retryTaskPool = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
            60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName("Raft-Retry-Pool");
                    return thread;
                }
            });


    /**
     * @Author czl
     * @Description 给netty服务端处理使用
     **/
    public static ExecutorService nettyServerAsyncPool = new ThreadPoolExecutor(6, 10,
            60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(1024*10),
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName("Raft-Server-Pool");
                    return thread;
                }
            });

    /**
     * @Author czl
     * @Description 给netty客户端处理使用
     **/
    public static ExecutorService nettyClientAsyncPool = new ThreadPoolExecutor(4, 10,
            60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(1024*10),
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName("Raft-Client-Pool");
                    return thread;
                }
            });



    /**
     * @Author czl
     * @Description 发送异步消息线程池
     **/
    public static ExecutorService sendAsyncMsgPool = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
            60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName("Send-Async-Pool");
                    return thread;
                }
            });


    /**
     * @Author czl
     * @Description 心跳任务线程池
     **/
    public static ScheduledExecutorService hearBeatAsyncPool = new ScheduledThreadPoolExecutor(2,
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName("Raft-Hear-Beat-Pool");
                    return thread;
                }
            });


    /**
     * @Author czl
     * @Description 日志拉取任务
     **/
    public static ScheduledExecutorService logPullAsyncPool = new ScheduledThreadPoolExecutor(1,
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName("Raft-Log-Pull-Pool");
                    return thread;
                }
            });


}
